#include "StdAfx.h"
#include "Parser.h"

void Parser::parse(const string& cmdLine, string& cmd, vector<string>& argv)
{
	char* str = const_cast<char*>(cmdLine.c_str());
	const char* delimiter = " "; 
	char* next; 

	next = strtok (str, delimiter);
	
	if( next != NULL ) 
		cmd = next;
	else
		cmd = "";

	toLower(cmd);
	while( (next = strtok(NULL,delimiter))  != NULL)
	{ 
		argv.push_back(next); 
	}
}

void Parser::parse(const string& s, vector<string>& result)
{
	char* str = const_cast<char*>(s.c_str());
	const char* delimiter = "/"; 
	char* next; 

	next = strtok (str, delimiter);
	result.push_back(next);
	while( (next = strtok(NULL,delimiter))  != NULL)
	{ 
		result.push_back(next); 
	}
}

void Parser::toLower(string& s)
{
	for(int i = 0; i != s.length(); ++i)
		s[i] = tolower(s[i]);
}

Parser::Parser(void)
{
}


Parser::~Parser(void)
{
}
